/**
 * Copyright @2016-present, Sumscope, Inc.
 * All rights reserved.
 */

const config = require('../config');

function isProd() {
  return process.env.NODE_ENV === 'production';
}

function wrapPrefix(str) {
  if (typeof str === 'string') {
    return config.server.prefix + ':' + str;
  } else {
    return str.map(s => config.server.prefix + ':' + s);
  }
}

function unwrapPrefix(str) {
  if (typeof str === 'string') {
    return str.substring(config.server.prefix.length + 1);
  } else {
    return str.map(s => str.substring(config.server.prefix.length + 1));
  }
}

function concat(to, from) {
  if (to instanceof Array) {
    from.forEach((item) => to.push(item));
  } else if (to instanceof Set) {
    from.forEach((item) => to.add(item));
  } else {
    throw new Error('not supported');
  }
  return to;
}

module.exports = {
  isProd,
  wrapPrefix,
  unwrapPrefix,
  concat
};
